﻿using System;
using System.Data;
using System.Web.UI;
using ltModel;

public partial class html_aspx_op : Page
{
    protected override void OnLoad(EventArgs e)
    {
        string o = Request.QueryString["o"], nid = Request.QueryString["nid"];
        if (Str.IsInt(nid))
        {
            Response.Charset = "gbk";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gbk");
            ltModel.BLL.article_content ac = new ltModel.BLL.article_content();
            ltModel.Model.article_content news = ac.GetModel(int.Parse(nid));
            if (news != null)
            {
                switch (o)
                {
                    case "hit":
                        ac.UpdateNewsHit(news.News_id);
                        WriteText(news.Hit.ToString());
                        break;
                    case "prev":
                        if (!WriteLink(string.Format(" news_id<>{0} and classid={1} and dat>'{2}' order by dat asc", news.News_id, news.Classid, news.Dat)))
                            WriteText("已经是第一篇了！");
                        break;
                    case "next":
                        if (!WriteLink(string.Format(" news_id<>{0} and classid={1} and dat<'{2}' order by dat desc", news.News_id, news.Classid, news.Dat)))
                            WriteText("已经是最后一篇了！");
                        break;
                }
            }
        }
        base.OnLoad(e);
    }

    bool WriteLink(string sql)
    {
        ltModel.BLL.article_content ac = new ltModel.BLL.article_content();
        DataTable table = ac.GetList("1", sql).Tables[0];
        if (table != null && table.Rows.Count > 0)
        {
            WriteText("<a href=\"/html/" + table.Rows[0]["link"].ToString() + "\">" + table.Rows[0]["title"].ToString() + "</a>");
            return true;
        }
        return false;
    }

    void WriteText(string text)
    {
        Response.Write(string.Format("document.write('{0}');", text));
    }
}